package vn.gq.udv.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

public class DialogUtils {
	
	private volatile static DialogUtils instance;
	private Context context;
	
	public DialogUtils(Context context) {
		this.context = context;
	}
	
	public static DialogUtils getInstance(Context ctx) {
		if (instance == null) {
			synchronized (DialogUtils.class) {
				if (instance == null) {
					instance = new DialogUtils(ctx);
				}
			}
		}
		return instance;
	}
	
	public void showConfirm(String msg, final OnDialogConfirmListener dlgConfirmListener) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(String.valueOf(msg))
		.setCancelable(true)
		.setPositiveButton("Có", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				if (dlgConfirmListener != null) dlgConfirmListener.onOk();
			}
		})
		.setNegativeButton("Không", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				if (dlgConfirmListener != null) dlgConfirmListener.onCancel();
			}
		});
		AlertDialog alertDialog = builder.create();
		alertDialog.setCancelable(false);
		alertDialog.show();
	}
	
	public void showMessage(String msg) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(String.valueOf(msg))
		.setCancelable(true)
		.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
			}
		});
		AlertDialog alertDialog = builder.create();
		alertDialog.setCancelable(false);
		alertDialog.show();
	}
	
	public interface OnDialogConfirmListener {
		void onOk();
		void onCancel();
	}
}
